#!/usr/bin/env bash
set -e

export SCRIPT_PATH=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Prepares Quarto source files for packaging
source "${SCRIPT_PATH}/../scripts/common/utils.sh"
source "${SCRIPT_PATH}/../../configuration"
source "${SCRIPT_PATH}/set_package_paths.sh"

if [ -z "$QUARTO_DENO" ]; then
  export QUARTO_DENO=$SCRIPT_PATH/../dist/bin/tools/$DENO_ARCH_DIR/deno
fi

export RUST_BACKTRACE=full
export DENO_NO_UPDATE_CHECK=1

# TODO: Consider generating a source map or something to get a good stack
# Create the Deno bundle
"$QUARTO_DENO" run --no-check --unstable-kv --unstable-ffi --allow-all --v8-flags=--stack-trace-limit=100 --importmap="${SCRIPT_PATH}/../../src/import_map.json" "$SCRIPT_PATH/bld.ts" $@
